import { defHttp } from '/@/utils/http/axios';
import { useGlobSetting } from '/@/hooks/setting';
const { domainUrl } = useGlobSetting();
var Api;
(function (Api) {
    Api["positionList"] = "/sys/position/list";
    Api["userList"] = "/sys/user/list";
    Api["roleList"] = "/sys/role/list";
    Api["queryDepartTreeSync"] = "/sys/sysDepart/queryDepartTreeSync";
    Api["queryTreeList"] = "/sys/sysDepart/queryTreeList";
    Api["loadTreeData"] = "/sys/category/loadTreeData";
    Api["loadTreeRoot"] = "/sys/category/loadTreeRoot";
    Api["loadDictItem"] = "/sys/category/loadDictItem/";
    Api["getDictItems"] = "/sys/dict/getDictItems/";
    Api["getTableList"] = "/sys/user/queryUserComponentData";
    Api["getCategoryData"] = "/sys/category/loadAllData";
    Api["downloadFile"] = "/sys/common/static";
})(Api || (Api = {}));
/**
 * 图片上传父路径
 */
export const uploadUrl = (domainUrl.substring(domainUrl.length - 1, domainUrl.length) === '/' ? domainUrl : domainUrl + "/") + 'sys/common/uploadImg';
/**
 * 文件上传父路径
 */
export const fileUploadUrl = (domainUrl.substring(domainUrl.length - 1, domainUrl.length) === '/' ? domainUrl : domainUrl + "/") + 'sys/common/uploadFile';
/**
 * 职务列表
 * @param params
 */
export const getPositionList = (params) => {
    return defHttp.get({ url: Api.positionList, params });
};
/**
 * 用户列表
 * @param params
 */
export const getUserList = (params) => {
    return defHttp.get({ url: Api.userList, params });
};
/**
 * 角色列表
 * @param params
 */
export const getRoleList = (params) => {
    return defHttp.get({ url: Api.roleList, params });
};
/**
 * 异步获取部门树列表
 */
export const queryDepartTreeSync = (params) => {
    return defHttp.get({ url: Api.queryDepartTreeSync, params });
};
/**
 * 获取部门树列表
 */
export const queryTreeList = (params) => {
    return defHttp.get({ url: Api.queryTreeList, params });
};
/**
 * 分类字典树控件 加载节点
 */
export const loadTreeData = (params) => {
    return defHttp.get({ url: Api.loadTreeData, params });
};
/**
 * 分类字典树控件 加载树
 */
export const loadTreeRoot = (params) => {
    return defHttp.get({ url: Api.loadTreeRoot, params });
};
/**
 * 根据字典code加载字典text
 */
export const loadDictItem = (params) => {
    return defHttp.get({ url: Api.loadDictItem, params });
};
/**
 * 根据字典code加载字典text
 */
export const getDictItems = (dictCode) => {
    return defHttp.get({ url: Api.getDictItems + dictCode }, { joinTime: false });
};
/**
 * 部门用户modal选择列表加载list
 */
export const getTableList = (params) => {
    return defHttp.get({ url: Api.getTableList, params });
};
/**
 * 加载全部分类字典数据
 */
export const loadCategoryData = (params) => {
    return defHttp.get({ url: Api.getCategoryData, params });
};
/**
 * 文件上传
 */
export const uploadFile = (params, success) => {
    return defHttp.uploadFile({ url: uploadUrl }, params, { success });
};
/**
 * 下载文件
 * @param url 文件路径
 * @param fileName 文件名
 * @param parameter
 * @returns {*}
 */
export const downloadFiles = (params) => {
    let url = Api.downloadFile + "/" + params.file;
    console.log("===params===:", url);
    return defHttp.get({ url: url }, params).then((data) => {
        console.log(data); // 获取服务端提供的数据
        let blob = new Blob([data]);
        let contentDisposition = data.headers['content-disposition'];
        let pattern = new RegExp('filename=([^;]+\\.[^\\.;]+);*');
        let result = pattern.exec(contentDisposition);
        // 使用decodeURI对名字进行解码
        let fileName = decodeURI(result[1]);
        let downloadElement = document.createElement('a');
        // 创建下载的链接
        let href = window.URL.createObjectURL(blob);
        downloadElement.style.display = 'none';
        downloadElement.href = href;
        // 下载后文件名
        downloadElement.download = fileName;
        document.body.appendChild(downloadElement);
        // 点击下载
        downloadElement.click();
        // 下载完成移除元素
        document.body.removeChild(downloadElement);
        // 释放掉blob对象
        window.URL.revokeObjectURL(href);
    });
};
/**
 * 【用于评论功能】自定义文件上传-方法
 */
export const uploadMyFile = (url, data) => {
    return defHttp.uploadMyFile(url, data);
};
